
package com.j2eefast.produce.pms.service;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.j2eefast.common.core.page.Query;
import com.j2eefast.common.core.utils.PageUtil;
import com.j2eefast.framework.sys.entity.SysUserEntity;
import com.j2eefast.framework.utils.Constant;
import com.j2eefast.framework.utils.UserUtils;
import com.j2eefast.produce.pms.entity.PmsParticipantEntity;
import com.j2eefast.produce.pms.entity.PmsParticipantUserEntity;
import com.j2eefast.produce.pms.entity.PmsProjectEntity;
import com.j2eefast.produce.pms.mapper.PmsParticipantMapper;
import com.j2eefast.produce.pms.mapper.PmsParticipantUserMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>参建人员</p>
 *
 * @author: summer
 * @date: 2021-05-29 16:47
 * @web: http://www.letukeji.cn
 * @version: 1.0.1
 */
@Service
@Transactional(readOnly = true)
public class PmsParticipantUserService extends ServiceImpl<PmsParticipantUserMapper, PmsParticipantUserEntity> {

	@Resource
	protected PmsParticipantUserMapper pmsParticipantUserMapper;


	/**
	 * 页面展示查询翻页
	 */
	public PageUtil findPage(Map<String, Object> params) {
		String userCode = (String) params.get("userCode");
		String userName = (String) params.get("userName");
		String iphone = (String) params.get("iphone");
		String participantUnit = (String) params.get("participantUnit");
		String userCode2 = (String) params.get("userCode2");
		String userName2 = (String) params.get("userName2");

		Page<PmsParticipantUserEntity> page = pmsParticipantUserMapper.findPage(
				new Query<PmsParticipantUserEntity>(params).getPage(),
				StrUtil.nullToDefault(userCode,""),
				StrUtil.nullToDefault(userName,""),
				StrUtil.nullToDefault(iphone,""),
				StrUtil.nullToDefault(participantUnit,""),
				StrUtil.nullToDefault(userCode2,""),
				StrUtil.nullToDefault(userName2,""),
				(String) params.get(Constant.SQL_FILTER));
		return new PageUtil(page);
	}

	public List<PmsParticipantUserEntity> findList(Map<String, Object> params) {
		String userCode = (String) params.get("userCode");
		String userName = (String) params.get("userName");
		List<PmsParticipantUserEntity> page = pmsParticipantUserMapper.findList(
				new Query<PmsParticipantUserEntity>(params).getPage(),
				StrUtil.nullToDefault(userCode,""),
				StrUtil.nullToDefault(userName,""),
				(String) params.get(Constant.SQL_FILTER));
		return page;
	}



	@Transactional(rollbackFor = Exception.class)
	public boolean deleteByIds(Long[] ids) {

		return pmsParticipantUserMapper.deleteByIds(ids);

	}
	@Transactional(rollbackFor = Exception.class)
	public boolean updateCheck(Long id) {
		Long userId= UserUtils.getUserInfo().getId();

		return pmsParticipantUserMapper.updateCheck(id ,userId);

	}
	public SysUserEntity getSysById(@Param("userId")Long userId){
		return pmsParticipantUserMapper.getSysById(userId);
	}

}
